//
//  WXPTextRemindView.m
//  提示 - 左侧叹号 - 中间文字 - 右侧关闭开关
//
//  Created by wxp on 2025/2/27.
//

#import "WXPTextRemindView.h"

@implementation WXPTextRemindView

#pragma mark - lazy
- (UIImageView *)imageTips{
    if (_imageTips == nil) {
        _imageTips = [UIImageView new];
        _imageTips.image = [UIImage imageNamed:@"icon-tips"];
        _imageTips.widthHeight = XY(18, 18);
    }
    return _imageTips;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.textColor = COLOR_LIGHT_GRAY;
        _labelContent.font = [UIFont boldSystemFontOfSize:12];
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 3;
    }
    return _labelContent;
}
-(UIButton *)btnClose{
    if (_btnClose == nil) {
        _btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
        WEAKSELF
        [_btnClose setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
            [NSObject clickFeedback];
            [weakSelf.btnClose addClickAnimate];
            if(weakSelf.blockClose){
                weakSelf.blockClose();
            }
        }];
        _btnClose.widthHeight = XY(14+2*LEFT_MARDIN, 14+2*LEFT_MARDIN);
        [_btnClose setImage:[UIImage imageNamed:@"icon-tips-close"] forState:UIControlStateNormal];
    }
    return _btnClose;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#FCFCE5"];
        self.width = SCREEN_WIDTH-2*LEFT_MARDIN;
        [self addSubView];
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.imageTips];
    [self addSubview:self.labelContent];
    [self addSubview:self.btnClose];
}

#pragma mark - 刷新view
- (void)resetViewWithContent:(NSString *)contentStr{
    self.imageTips.left = 12;
    self.btnClose.right = self.width;
    
    [self.labelContent fitTitle:contentStr variable:self.btnClose.left-self.imageTips.right-8];
    self.labelContent.leftTop = XY(self.imageTips.right+8, 12);
    
    self.height = self.labelContent.bottom+self.labelContent.top;
    
    self.imageTips.centerY = self.height/2;
    self.btnClose.centerY = self.height/2;
    
    [GlobalMethod setRoundView:self color:[UIColor clearColor] numRound:8 width:0];
    self.left = LEFT_MARDIN;
}

- (void)resetHiddenCloseBtnViewWithContent:(NSString *)contentStr{
    self.imageTips.left = 12;
    self.btnClose.hidden = true;
    
    [self.labelContent fitTitle:contentStr variable:self.width-self.imageTips.right-8];
    self.labelContent.leftTop = XY(self.imageTips.right+8, 12);
    
    self.height = self.labelContent.bottom+self.labelContent.top;
    
    self.imageTips.centerY = self.height/2;
    
    [GlobalMethod setRoundView:self color:[UIColor clearColor] numRound:8 width:0];
    self.left = LEFT_MARDIN;
}


@end
